package com.yx.fx.webApi.job.config;

import com.yx.fx.webApi.job.AutoAllocateStewardshipManagerJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzJobConfig {


    /**
     * 关联具体要执行的Job业务类
     *
     * @return
     */
    @Bean
    public JobDetail autoAllocate() {
        return JobBuilder.newJob(AutoAllocateStewardshipManagerJob.class)//Job业务类
                .withIdentity("autoAllocateStewardshipManagerJob")//给具体Job业务类取一个唯一id
                .usingJobData("msg", "自动分配管户经理给新注册企业")
                .storeDurably()//即使没有trigger也不需要删除该jobDetail
                .build();
    }

    @Bean
    public Trigger autoAllocateTrigger() {
        //1.corn表达式
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 1 * * ?");//一分钟执行一次autoAllocate任务
        return TriggerBuilder.newTrigger()//创建触发器去执行job
                .forJob(autoAllocate())//指定触发器要执行的job
                .withIdentity("autoAllocateStewardshipManagerJobTrigger")//给新建的trigger起个唯一id
                .withSchedule(cronScheduleBuilder)//添加cron表达式
                .build();
    }
}
